#ifndef FORM_YS_ENV_H
#define FORM_YS_ENV_H

#include <QWidget>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include "pub_pop_get_item.h"
#include "pub_pop_delay.h"
#include "pub_sqthread.h"
#include <QModelIndex>
#include <QStandardItemModel>
#include <QComboBox>

#include <QTimer>

class tipShowThread ;

namespace Ui {
class Form_ys_env;
}

class Form_ys_env : public QWidget
{
    Q_OBJECT

public:
    explicit Form_ys_env(QWidget *parent = nullptr);
    ~Form_ys_env();

    void closeEvent(QCloseEvent *event);


signals:
    void destroyW( QString );

private slots:

    void display_reci_days();
    void threadMsg(QString);
    void saveDiagItem();
    void saveFormUsage();
    void fillCombo(QComboBox *cbb, QString sq );
    void on_pbSearchS_clicked();
    void tvGroupDetailRefresh();
    void on_tbAdd_clicked();
    bool check_constrain_status(int mode);

    void on_tbRemove_clicked();

    void on_pbSearchD_clicked();

    void on_tvDest_doubleClicked(const QModelIndex &index);

    void on_rb01_clicked();

    void on_rb02_clicked();

    void on_rb03_clicked();

    void on_rb04_clicked();

    void on_pbFresh_clicked();

    void on_pbExit_clicked();

    void on_tvDict_doubleClicked(const QModelIndex &index);

    void on_tvDict_clicked(const QModelIndex &index);

    void on_tvValue_doubleClicked(const QModelIndex &index);

    void on_tvValue_clicked(const QModelIndex &index);

    void on_pbAdd_clicked();

    void on_pbDel_clicked();

    void on_rbKey_clicked();

    void on_rbCode_clicked();

    void on_pbSearchDiag_clicked();

    void on_pbSearchItem_clicked();

    void on_tbAdd_2_clicked();

    void on_tbRemove_2_clicked();

    void on_tvDiag_doubleClicked(const QModelIndex &index);

    void on_tvItem_doubleClicked(const QModelIndex &index);

    void on_pbSearchRelated_clicked();

    void on_rbD2I_clicked();

    void on_rbI2D_clicked();

    void on_rbCompared_clicked();

    void on_rbAll_clicked();

    void on_pbFreshGroup_clicked();

    void on_tvGroup_clicked(const QModelIndex &index);

    void on_tvGroupDetail_doubleClicked(const QModelIndex &index);

    void on_tvGroupDetail_clicked(const QModelIndex &index);

    void on_leSearchG_returnPressed();

    void on_pbRemoveG_clicked();

    void on_pbSaveG_clicked();

    void on_pbAddItem_clicked();

    void on_pbRemoveItem_clicked();

    void on_pbSaveFolderOrd_clicked();

    void on_leKeyS_returnPressed();

    void on_leKeyD_returnPressed();

    void on_leKeyDiag_returnPressed();

    void on_leKeyItem_returnPressed();

    void on_leKeyRelated_returnPressed();

    void on_rbDoct_clicked();

    void on_rbCom_clicked();

    void on_toolButton_clicked();

    void on_tvSourceIcd_clicked(const QModelIndex &index);

    void on_tvSourceIcd_doubleClicked(const QModelIndex &index);

    void on_tvSourceIcpc_clicked(const QModelIndex &index);

    void on_tvDest_clicked(const QModelIndex &index);

    void on_cbbKey_currentTextChanged(const QString &arg1);

    void on_pbCreateFolder_clicked();

    void on_pbSearchRelated_2_clicked();

    void on_tbAdd_3_clicked();

    void on_tv_doseform_doubleClicked(const QModelIndex &index);

    void on_tv_usage_doubleClicked(const QModelIndex &index);

    void on_tvItem_clicked(const QModelIndex &index);

    void on_tvDiag_clicked(const QModelIndex &index);

    void on_tvRelated_clicked(const QModelIndex &index);

    void on_tvRelated_doubleClicked(const QModelIndex &index);

    void on_pbSearchDiag_2_clicked();

    void on_tb_diag_into_rule_clicked();

    void on_tb_diag_leave_rule_clicked();

    void on_pb_new_rule_clicked();

    void on_pb_fresh_conflict_rules_clicked();

    void on_tv_rule_conflict_clicked(const QModelIndex &index);

    void on_tv_rule_conflict_doubleClicked(const QModelIndex &index);

    void on_pbSearchDiag_3_clicked();

    void on_pb_refresh_rule_constrain_clicked();

    void on_pb_save_rule_age_clicked();

    void on_pb_save_rule_gend_clicked();

    void on_tv_drug_for_rule_constrain_clicked(const QModelIndex &index);

    void on_tv_drug_for_rule_constrain_doubleClicked(const QModelIndex &index);

    void on_tv_rule_constrain_clicked(const QModelIndex &index);

    void on_tv_rule_constrain_doubleClicked(const QModelIndex &index);

    void on_pb_remove_rule_constrain_clicked();

    void on_pb_remove_conflict_clicked();

    void on_pb_diag_gend_clicked();

    void on_tbRemove_3_clicked();

    void on_cbb_dept_currentIndexChanged(const QString &arg1);

    void on_pb_clear_conflict_items_clicked();

    void on_tab_recipe_check_currentChanged(int index);

    void on_pb_save_reci_days_clicked();

    void on_rb_tr_diag_clicked();

    void on_rb_tr_symptom_clicked();

    void on_pb_search_diag_clicked();

    void on_le_key_diag_returnPressed();

    void on_le_key_diag_tr_returnPressed();

    void on_pb_search_diag_tr_clicked();

    void on_le_key_symptom_tr_returnPressed();

    void on_pb_search_symptom_tr_clicked();

    void on_le_key_relate_med_tr_returnPressed();

    void on_pb_search_med_tr_clicked();

    void on_tb_remove_med_tr_clicked();

    void on_tb_add_med_tr_clicked();

    void on_tv_relate_med_tr_clicked(const QModelIndex &index);

    void on_tv_relate_med_tr_doubleClicked(const QModelIndex &index);

    void on_tv_diag_med_clicked(const QModelIndex &index);

    void on_tv_diag_tr_clicked(const QModelIndex &index);

    void on_tv_symptom_tr_clicked(const QModelIndex &index);

    void on_tv_diag_med_doubleClicked(const QModelIndex &index);

    void on_tv_diag_tr_doubleClicked(const QModelIndex &index);

    void on_tv_symptom_tr_doubleClicked(const QModelIndex &index);

    void on_tabWidget_currentChanged(int index);

    void on_pb_dic_type_clicked();

    void on_tv_reci_ck_doubleClicked(const QModelIndex &index);

    void on_tv_reci_ck_clicked(const QModelIndex &index);

    void on_pb_reci_remove_clicked();

    void on_tb_search_item_clicked();

    void on_le_item_code_returnPressed();

private:
    Ui::Form_ys_env *ui;

    Pub_pop_get_item * dlgp;
    Pub_pop_delay * dlgp1;
    sqThread * sqth;
    QStringList sqlMsg;


    QSqlQuery *qrm, *qrmt, *qrmt2, *qro, *qrot;
    QSqlQueryModel *mdSourceIcd,*mdSourceIcpc, *mdDest, *mdDest_2 , *mdPop, *mdDict, *mdValue;//
    QSqlQueryModel *mdDiag, *mdItem, *mdGroupDetail ;//,
    QSqlQueryModel *md_diag_med, *md_diag_tr, *md_symptom_tr, *md_relate_med_tr ;//,
    QStandardItemModel *mdRelated, *mdGroup;

    QSqlQueryModel *md_form, *md_usage, *md_reci_ck_days ;//  药品剂型，用法,处方限量
    QStandardItemModel *md_form_usage;

    QSqlQueryModel *md_drug_for_rule_conflict, *md_drug_in_rule_conflict , *md_rule_conflict;//  药品冲突

    QSqlQueryModel *md_drug_for_rule_constrain ,*md_rule_constrain;//药品限制

    QString sq;

    QString dicMode;   //字典性质 ，dept科室,all全院
    QString IcpcDicType;   //icpc字典类别 ，0 就诊原因， 1非药品项目，  2诊断，  3药品
    QString popRetStr;

    QModelIndex mdidx;  //mdDict 索引
    QString item_code;  //药品组套的药品,
    int item_seq;       //药品组套的排序
    QString groupId, folderId;    //组套ID

    bool noICPC;    // 忽略icpc编码

    QString dept_constrain; //限制用户所能操作的诊室范围
    QString depts_code;  //

    bool initial_finished;  //界面初始化
    bool current_item_is_group;//当前非药品项目是否为组合

    QMap<QString, QString> med_tr_relate;

    QString fee_name_code,dept_name_code;//收费类别，诊室
    QString reci_ck_item_name,reci_ck_item_code; //处方限量项目名称代码

};



#endif // FORM_YS_ENV_H
